<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"  
      xmlns:h="http://java.sun.com/jsf/html"  
      xmlns:f="http://java.sun.com/jsf/core"  
      xmlns:p="http://primefaces.org/ui"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:ui="http://java.sun.com/jsf/facelets">  
    <ui:composition template="/templete.xhtml">
        <ui:define name="conteudo">
            <h:form id="novo">
                <p:commandButton id="btnNovo" value="Cadastrar novo posto" rendered="#{postoCtrl.editar}"
                                 actionListener="#{postoCtrl.novo()}" update=":novo,:cadastro"/>
            </h:form>
              <p:panel style="width: 80%;" id="painel" header="CADASTRO DE POSTO" >

            <h:form id="cadastro" enctype="multipart/form-data">
                <p:messages id="messages"/> 
                <p:growl id="growl"/>

                <p:panelGrid id="pnlGrid"  columns="2" style="width: 100%;border: none " >
                    <f:facet name="header">
                        Cadastro de Postos
                    </f:facet>                

                    <p:column >
                        <h:outputLabel for="nomePosto" value="Nome :"/>
                        <p:spacer height="0" width="100"/>
                    </p:column>
                    <p:column>
                        <p:inputText id="nomePosto"   style="width: 75%" value="#{postoCtrl.posto.pstNome}" label="nomePoseto"
                                     required="true" requiredMessage="Informe o nome do posto" readonly="#{postoCtrl.editar}"/><p:message for="nomePosto"/>
                    </p:column>



                    <p:column>
                        <h:outputLabel for="siglaPosto" value="Sigla :"/>
                        <p:spacer height="0" width="100"/>
                    </p:column>
                    <p:column>
                        <p:inputText id="siglaPosto" style="width: 75%"   value="#{postoCtrl.posto.pstSigla}" label="siglaPoseto"
                                     required="true" requiredMessage="Informe a sigla" readonly="#{postoCtrl.editar}" /><p:message for="siglaPosto"/>
                    </p:column>     

                </p:panelGrid >

                <p:spacer height="50"/>
                <p:commandButton  value="Adcionar Combustível" onclick="dlgCmb.show();" type="button" style="font-size: 12px" icon="ui-icon-disk"/>
                <p:dataTable id="combustiveis" value="#{postoCtrl.listaPostoComustivel}"  emptyMessage="Não exite combustíveis cadastrados para este posto" var="comb">

                    <f:facet name="header">
                        COMBUSTÍVEIS
                    </f:facet>
                    <p:column>
                        <f:facet name="header">
                            Preço
                        </f:facet>
                        <p:inputMask mask="R$ 9,999" id="preco" value="#{comb.precoCombustivel}">
                            <f:converter converterId="convertMask"/>
                        </p:inputMask>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            Combustível
                        </f:facet>
                        <h:outputText value="#{comb.combustivel.cmbDescricao}"/>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            Excluir 
                        </f:facet>
                        <p:commandButton immediate="true"  icon="ui-icon-circle-minus" process="@form"  update="combustiveis"  actionListener="#{postoCtrl.removerCombustivelPosto(comb)}"/>
                    </p:column>
                    
                </p:dataTable>
                
                <p:spacer height="50"/>
                 
                <p:row>
                    <p:commandButton value="Salvar" update="@form" process="@form" action="#{postoCtrl.salvar}"/>
                </p:row>
            </h:form>
            
          


            
            
          



            <p:spacer height="50"/>
            <h:form  id="combustivel">
                <p:dialog id="dlgCmb" modal="false" width="800" widgetVar="dlgCmb">

                    <p:dataTable emptyMessage="Não exitem combustíveis cadastrados" var="comb" value="#{combustivelCtrl.listar()}">
                        <f:facet name="header">
                            COMBUSTÍVEIS
                        </f:facet>
                        <p:column>
                            <f:facet name="header">
                                Preço
                            </f:facet>
                            <h:outputText value="#{comb.cmbValoratual}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                Combustível
                            </f:facet>
                            <h:outputText value="#{comb.cmbDescricao}"/>
                        </p:column>
                        <p:column>
                             <f:facet name="header">
                               Adcionar
                            </f:facet>
                            <p:commandButton  immediate="true" icon="ui-icon-circle-plus" id="submitButton" update=":cadastro:combustiveis" oncomplete="dlgCmb.hide();" actionListener="#{postoCtrl.addCombustivelPosto(comb)}"/>  
                        </p:column>
                    </p:dataTable>

                </p:dialog>
            </h:form>
        </p:panel>
        </ui:define>
        
    </ui:composition>
</html>

